/**
 * 
 */
package com.glela.platform.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glela.cache.redis.RedisKeys;
import com.glela.cache.redis.RedisUtil;
import com.glela.constant.SymbolConstant;
import com.glela.common.util.CryptUtils;


/**
 * token存储service
 * @author liujie
 *
 */

@Service
public class TokenInnerRedisService{
	@Autowired
 	 public RedisUtil redis;
	
	static int TIME_SECONDS = 30*60*10;
  	 
 	 /**
 	 * @param key
 	 * @param tokenDesc
 	 */
 	public synchronized String saveVideoUserToken(long videoId,long userId){
		String keyTmp = RedisKeys.TOKEN_USER_VIDEO+userId;
 		long timeStamp = System.currentTimeMillis();
		String tokenSrc =videoId+"_" +userId+"_"+timeStamp;
 		String tokenDes = CryptUtils.getUUID();
 		String res = tokenSrc+SymbolConstant.SHARP_SYMBOL+tokenDes;
 		redis.set(keyTmp, res, TIME_SECONDS);
 		return tokenDes;
 		 
  	 }
 	
 	
 	
  
 	/**
 	 * @param key
 	 * @return
 	 */
 	public String  getVideoUserToken(String key){
 		String token  = redis.get(key);
 		removeVideoUserToken(key);
 		return token;
 	}
 	
 	
 	public void  removeVideoUserToken(String key){
 		  redis.del(key);
  	 }
}
